package com.example.tired1.spinnertext_xx14120200131;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Spinner;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    TextView textView;
    Spinner spinner;
    AutoCompleteTextView autoview;


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        autoview =(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView2);
        String [] arr={"aa","aab","aac"};
        ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(
                MainActivity.this,
                R.layout.spinner_item,
                arr);
        autoview.setAdapter(adapter3);


                setContentView(R.layout.activity_main);
        textView=(TextView)findViewById(R.id.textView2);
        spinner=(Spinner)findViewById(R.id.spinner);
        spinner.setAdapter(adapter3);
//        String[] array={"北京","上海","深圳","广州","大连"};
// //      ArrayAdapter<String> adapter=new ArrayAdapter<String>(MainActivity.this,//上下文
//  //            android.R.layout.simple_spinner_item,//显示的样式
////               array);//数据源
//              //声明适配器
//        ArrayAdapter<String> adapter=new ArrayAdapter<String>(MainActivity.this,//上下文
//                R.layout.spinner_item,//显示的样式
//                array);//数据源
//        //声明适配器
//        //adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
//        //设置下拉按钮样式
//        spinner.setAdapter(adapter);//绑定当前适配器
//        spinner.setPrompt("请选择城市");

        //在XML里定义数据的spinner使用方式
        String[] zhuanye=getResources().getStringArray(R.array.zhuanye);
        ArrayAdapter<String> adapter2=new ArrayAdapter<String>(MainActivity.this,
                R.layout.spinner_item,
                zhuanye);
        spinner.setAdapter(adapter2);

        spinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String text=((TextView)view).getText().toString();
                textView.setText(text);

            }
            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
            });


        }








}
